package interview;

import java.util.LinkedList;
import java.util.List;

public class interview_17_12 {
    public TreeNode convertBiNode(TreeNode root) {
        TreeNode head=root;
        if(root==null) return root;
        while(head.left!=null){
            head=head.left;
        }
        List<TreeNode> list = new LinkedList<>();
        inorder(list,root);
        for(int i=0;i<list.size()-1;++i){
            list.get(i).left=null;
            list.get(i).right=list.get(i+1);
        }
        list.get(list.size()-1).left=null;
        list.get(list.size()-1).right=null;
        return head;
    }
    public void inorder(List<TreeNode> list,TreeNode node){
        if(node==null) return;
        inorder(list,node.left);
        list.add(node);
        inorder(list,node.right);
    }
}
